package com.changgou.goods.controller;
        import com.changgou.entity.Result;
        import com.changgou.entity.StatusCode;
        import org.springframework.web.bind.annotation.ControllerAdvice;
        import org.springframework.web.bind.annotation.ExceptionHandler;
        import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice  //意为控制器增强
public class BaseExceptionHandler {

    @ExceptionHandler(value = Exception.class)  //拦截异常，value表示要拦截的异常类型。
    @ResponseBody
    public Result error(Exception e){
        System.out.println(e.getMessage());
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }
}
